using System.Reflection;
using System;
using Microsoft.Practices.CompositeWeb.Utility;

namespace WCSFContrib.Extensions.EventBroker
{
	public class MemberReference<T> : IEquatable<MemberReference<T>> where T : MemberInfo
	{
		private readonly string topic;
		private readonly T info;

		public MemberReference(string topic, T info)
		{
			Guard.ArgumentNotNullOrEmptyString(topic, "topic");
			Guard.ArgumentNotNull(info, "info");

			this.topic = topic;
			this.info = info;
		}

		public string Topic
		{
			get { return topic; }
		}

		public T Info
		{
			get { return info; }
		}

		public Type DeclaringType { get { return info.DeclaringType; } }

		#region Equals implementation
		public override bool Equals(object obj)
		{
			MemberReference<T> o = obj as MemberReference<T>;
			return o != null && Equals(o);
		}

		public bool Equals(MemberReference<T> other)
		{
			return topic.Equals(other.topic) &&
					 info.Equals(other.info);
		}

		public override int GetHashCode()
		{
			return topic.GetHashCode() ^ info.GetHashCode();
		}
		#endregion
	}
}